// TOWN SCRIPT
//    Town 0: Abandoned town.

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documentation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

body;

beginstate INIT_STATE;
// Called upon entering

if(get_flag(0,0) == 0) {
	reset_dialog();
	add_dialog_str(0,"You emerge from the thick forests that cover the island into a small town. Strong stone buildings stand amongst the trees, and a small lake catches the falling rain, filling the air with a gentle hiss.",0);
	add_dialog_str(1,"Looking around, you once again fail to spot any kind of living creature, human or otherwise, and the sound of the cutting wind carries no birdsong.",0);
	add_dialog_str(2,"Up ahead, though, you spot an obelisk by the side of the road. You have to strain a little, but you can just about make out what it says. It carries no greeting, no town name. Instead, it has 5 words scratched into it on all sides:",0);
	add_dialog_str(3,"_Don't blink - watch the statues._",0);
	add_dialog_str(4,"Keeping your hand close to your weapon, you march on. Maybe you'll find some kind of clue as to what in the world is going on further in.",0);
	run_dialog(1);
	set_flag(0,0,1);
}

if(get_flag(0,11) == 1) {
	set_terrain(45,16,0);
}
break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
// Called every turn.
break;

//Firepit in smithy
beginstate 10;
	if(get_flag(0,1) == 0) {
		message_dialog("This firepit is full of coal, all completely cold - it hasn't been used for a long while.","You nose around in it for a moment. not quite sure what you're looking for. Unsurprisingly, you don't find anything. You move on.");
		set_flag(0,1,1);
	} else {
		message_dialog("The firepit is still cold, and still completely uninteresting. You move on.","");
	}
break;

//Intro to Smithy
beginstate 11;
	if(get_flag(0,2) == 0) {
		message_dialog("You enter this small building, which is unmistakably a small blacksmith's workshop. Two large anvils sit to the south, unused, and everything is covered in a layer of dust.","Perhaps whoever worked here left some gear when they left - it'd be worth a look, at any rate.");
		set_flag(0,2,1);
	}
break;

//Western box - empty
beginstate 12;
	if(get_flag(0,3) == 0) {
		message_dialog("You look inside this chest and find bits of thread, a few needles and a lot of junk - nothing that is useful to you in anyway.","You close the box and move on.");
		set_flag(0,3,1);
	} else {
		message_dialog("You don't bother looking inside this chest again.","");
	}
break;

//Eastern box - nice cloak.
beginstate 13;
	if(get_flag(0,4) == 0) {
		reset_dialog();
		add_dialog_str(0,"This chest is almost completely empty - the only thing inside is a cloak bundled up at the bottom.",0);
		add_dialog_str(1,"You fetch it out and take a look at it. It's still in suprisingly good shape, considering that it's been left in a damp box for goodness knows how long. Do you want to take it?",0);
		add_dialog_choice(0,"Yes, take the cloak.");
		add_dialog_choice(1,"No, leave it alone.");
		if(run_dialog(1) == 1) {
			message_dialog("You take the cloak, and close the chest behind you.","");
			reward_give(117);
			set_flag(0,4,1);
			end();
		} else {
			message_dialog("You put the cloak back and close the chest before moving on.","");
			end();
		}
	}
break;

//Tailor's shop greeting
beginstate 14;
	if(get_flag(0,5) == 0) {
		message_dialog("As you enter this building your heart skips a beat - fortunately though, the two motionless figures aren't made of stone - they're only dressmaker's dummies.","This must be a tailor's shop; every bit as dusty as everywhere else in town, and completely deserted. Whoever left did so in a hurry - there is a half-finished shirt still on the counter.");
		set_flag(0,5,1);
	}
break;

//Generic house box
beginstate 15;
	if(get_flag(0,15) == 0) {
	message_dialog("This box contains a wide collection of personal items - combs, books, underwear, coin purses - the sorts of things which aren't particularly useful to you to right now (you are already wearing underwear, for example).","You close the chest and move on.");
	} else {
		message_dialog("This box contains a wide collection of personal items - combs, books, underwear, coin purses - the sorts of things which still aren't particularly useful to you to right now.","You close the chest and move on.");
	}
break;

//Inn greeting
beginstate 16;
	if(get_flag(0,6) == 0) {
		reset_dialog();
		add_dialog_str(0,"You enter this large building; most probably a bar or pub. Various flagons and uncorked bottles line the tables, their contents now dust and their drinkers gone.",0);
		add_dialog_str(1,"The floor is covered with dust and rubbish; broken plates, cutlery and food wrappings. It's almost as if everybody just got up and left, leaving everything behind.",0);
		add_dialog_str(2,"Curiously, you notice that a number of torches hang from the walls, still lit. You blow on one of them, but the flame doesn't go out - they must be enchanted somehow, which would explain why they've kept burning for so long.",0);
		add_dialog_str(3,"Clearly whatever people built this place were skilled in the magical arts. You wonder again where they went.",0);
		run_dialog(1);
		set_flag(0,6,1);
	}
break;

//Cauldrons
beginstate 17;
	if(get_flag(0,7) == 0) {
		message_dialog("These cauldrons are empty, apart from a nasty brown sludge in the bottom of them - you dread to think what it was before it rotted away to what you see now.","Needless to say, you don't serve any up for yourself.");
		set_flag(0,7,1);
	}
break;

//Western box in inn - empty
beginstate 18;
	if(get_flag(0,8) == 0) {
		message_dialog("This box is completely empty - save an unearthly amount of dust and what looks like ancient rodent droppings.","You close the lid and move on.");
		set_flag(0,8,1);
	} else {
		message_dialog("You've already searched this box.","");
	}
break;

//Eastern box in inn - rotten
beginstate 19;
	if(get_flag(0,9) == 0) {
		message_dialog("This box, you would guess, once contained several sacks of fine meal - now all that is left are a few threadbare sacks and the lingering smell of flour and dough.","You close the box and move on.");
		set_flag(0,9,1);
	} else {
		message_dialog("You've already searched this box.","");
	}
break;

//Boxes in Bakekery ;)
beginstate 20;
	message_dialog("Whatever was once in here is now gone - rotted away, most probably. All that is left is a fine dust at the bottom.","You close it back up and move on.");
break;

//Bakekery again
beginstate 21;
	if(get_flag(0,10) == 0) {
		message_dialog("This small building still smells, ever-so-faintly, of freshly-baked bread. That, coupled with the rank of ovens on the western wall, immediately mark this place as a baker's kitchen.","Of course, the ovens are cold now and any bread that might have been left here has most likely rotted away now - that is if rats didn't get to it first.");
		set_flag(0,10,1);
	} 
break;

//Oh my, it's a statue!
beginstate 22;
	if(get_flag(0,11) == 0) {
		reset_dialog();
		add_dialog_str(0,"As you round this corner you come face-to-face with another statue of an angel. A closed portcullis sits between you and it.",0);
		add_dialog_str(1,"Remembering what the sign at the other end of town said, you keep your eyes firmly on it. It seems to be covering its eyes with an arm for some reason, but its other hand is pointing in your direction.",0);
		add_dialog_str(2,"At first, you think it's pointing at you - your pulse quickens and you reach for your weapon. However, you realise that it's pointing behind you, instead.",0);
		if(get_flag(0,12) == 0) {
			add_dialog_str(3,"You quickly flash your eyes behind you and spot a large building atop a small hill. Puzzled, you turn back to the statue, but it's gone! You only let it out of your sight for a moment! That's impossible!",0);
		} else {
			add_dialog_str(3,"You quickly flash your eyes behind you and see that the statue is pointing at the large building you tried to enter earlier. Puzzled, you turn back to the statue - it's gone! You only let it out of your sight for a moment! That's impossible!",0);
		}
		run_dialog(1);
		set_terrain(45,16,0);
		
		reset_dialog();
		add_dialog_str(0,"You look around - the portcullis must be controlled from somewhere nearby - and sure enough you spot a wheel in the nearby guardpost that looks promising.",0);
		add_dialog_str(1,"Trying that first seems obvious, but if that doesn't work you'll probably have to go to the building the angel pointed out - and hope it's not a trap.",0);
		run_dialog(1);
		set_flag(0,11,1);
	}	
break;

//Box in guardpost
beginstate 23;
	if(get_flag(0,13) == 0) {
		message_dialog("This box is completely empty, apart from an unearthly amount of dust and what looks like ancient rodent droppings.","You close the lid and move on.");
		set_flag(0,13,1);
	} else {
		message_dialog("You've already searched this box.","");
	}
break;

//Wheel in guardpost
beginstate 24;
	reset_dialog();
	add_dialog_str(0,"This large heavy wheel, you assume, controls the gates just outside of the guardpost. Do you wish to turn the wheel?",0);
	add_dialog_choice(0,"Yes, turn it.");
	add_dialog_choice(1,"No, leave it alone.");
	if(run_dialog(1) == 1) {
		message_dialog("With a huge effort you manage to get the wheel to turn, slowly at first, but eventually, as the rust falls away, quicker and quicker.","");
		play_sound(-99);
		flip_terrain(41,17);
		flip_terrain(41,16);
		flip_terrain(41,15);
	} else {
		message_dialog("You decide to leave the wheel alone for the moment.","");
	}	
break;

//Temple
beginstate 25;
	if(get_flag(0,11) == 0) { //not had statue point the way
		message_dialog("You approach this large building and try the doors. Unfortunately, they seem to be locked, despite the fact that you can't see any visible keyholes.","It seems that you won't be able to get inside. You move on.");
		set_flag(0,12,1);
		block_entry(1);
	} else {
		if(get_flag(0,14) == 0) {
			message_dialog("You approach the large building the statue was pointing out earlier and try the doors. They open immediately, and you walk inside.","");
			set_flag(0,14,1);
			move_to_new_town(3,16,21);
		} else {
			move_to_new_town(3,16,21);
		}
	}
break;





